<?php



require ROOT_PATH.'/Helper/admin_abstract.php';

class Action extends admin_abstract
{
    function index()
    {
        $data = _model('comment')->getList('ORDER BY add_time DESC', new Pager(20));
        $this->view->assign($data);
        $this->view->display('admin/comment_manage.html');
    }
    
    function edit()
    {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $id = _POST('id', 0);
            $info = _POST('info', array());
            if (!$id) {
                $this->msg('Lacking parameter');
            }
            _model('comment')->update(array('id'=>$id), $info);
            $this->msg('Operation was successful!', "admin/comment_manage.html");
        } else {
            $id = _GET('id', 0);
            if (!$id || !$info = _model('comment')->read(array('id'=>$id))) {
                $this->msg('Lacking parameter');
            }
            $this->view->assign('info', $info);
            $this->view->display('admin/comment_edit.html');
        }
    }
    
    function delete()
    {
        $id = _GET('id', 0);
        if (!$id) {
            $this->msg('Lacking parameter');
        }
        _model('comment')->delete(array('id'=>$id));
        $this->redirect();
    }
}

?>